package co.chonghao.ch_kuaichong_user.utils;

import android.content.Context;
import android.widget.Toast;

import co.chonghao.ch_kuaichong_user.app.App;
import co.chonghao.ch_kuaichong_user.ui.views.MyToast;


public class ToastUtils {

    private static Context mContex = App.getApp();

    public static void showToast(String info) {
        Toast.makeText(mContex, info, Toast.LENGTH_LONG).show();
    }


    private static MyToast mToast;

    /**
     * 显示自定义toast
     * @param text
     */
    public static void showMyToast( String text) {
        if (mToast != null) {
            mToast.setText(text);
        } else {
            mToast = MyToast.makeText(mContex,text,MyToast.LENGTH_SHORT);
        }
        mToast.setWarningVisibility(false);
        mToast.show();
    }
    public static void showMyResToast( int resId) {
        if (mToast != null) {
            mToast.setText(mContex.getResources().getString(resId));
        } else {
            mToast = MyToast.makeText(mContex,mContex.getResources().getString(resId),MyToast.LENGTH_SHORT);
        }
        mToast.show();
    }

    /**
     * 带警告的toast
     * @param text
     * @param duration
     */
    public static void showWarningToast( String text, int duration) {
        if (mToast != null) {
            mToast.setText(text);
        } else {
            mToast = MyToast.makeText(mContex,text,duration);
        }
        mToast.setWarningVisibility(true);
        mToast.show();
    }
}